<template>
	<view class="wf-box" :style="{ paddingTop: totalheight }">
		<view class="head" :style="{ paddingTop: navBarHeight }">
			<view class="head-np">
				<image @click="back()" class="back" src="@/static/img/chat-09.png" mode="widthFix"></image>
				<view class="title">{{ friendName ? friendName : '我' }}的朋友圈</view>
			</view>
		</view>

		<view class="main">
			<view class="item" @click="details(item)" v-for="(item,i) in ownFirendList" :key="i">
				<view class="item_top">
					<image :src="item.avatar" mode="aspectFill"></image>
					<view class="item_name">
						<view>
							{{item.nikeName}}
							<!-- <image src="@/static/img/k_icon1.png" mode="widthFix"></image> -->
							<!-- <image src="@/static/img/k_icon2.png" mode="widthFix"></image> -->
						</view>
						<view>ID:{{ item.userId }}</view>
					</view>
					<view class="del" @click.stop="openPopup(item.id)">
						<uni-icons type="trash" size="22" v-if="!friendName"></uni-icons>
						<!-- <image src="@/static/img/k_icon3.png" mode="widthFix"></image> -->
						<view class="item_time">{{ item.createTime }}</view>
					</view>
				</view>
				<view class="warp">
					<view class="text" :class="true ? '' : 'ellipsis'" id="ellipsis_box">
						<text>{{ item.text }}</text>
					</view>
				</view>
				<view class="item_img" v-if="true">
					<view class="equall-img" v-for="itep in item.medias">
						<image :src="itep" mode="aspectFill"></image>
					</view>
				</view>
				<view class="item_bottom" v-if="false">
					<view class="like-box">
						<uni-icons v-if="true" type="hand-up-filled" size="22" color="#FC8925"></uni-icons>
						<view class="like-list">
							<text v-for="itex in item.likeVOList">{{ itex.nickName }}</text>
						</view>
					</view>
					
					<view class="firend-comments">
						<image src="@/static/img/comment.png"></image>
						<view class="comment-list">
							<view class="comment-item">集团你问他流口水的公路上</view>
						</view>
					</view>
				</view>
			</view>
			<view v-if="tabIndex==0" class="friend">
				<image src="@/static/img/not-icon.png" mode="widthFix"></image>
				<view class="">暂未开放</view>
			</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="popup-box">
				<view class="popup-title">删除朋友圈？</view>
				<view class="popup-sub">确认要删除本条朋友圈</view>
				<view class="popup-footer">
					<view class="cancle" @click="closePopup()">取消</view>
					<view class="confim" @click="deletes()">确定</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import navBarMixin from '@/mixin/navBarMixin.js'
	import { getOwnFriendCircleApi , getCircleByFriendIdApi,deleteFriendCircle } from '@/api/api.js'
	export default {
		data() {
			return {
				firendCircleType: '',
				ownFirendList: [],
				friendId: '', // 好友id
				friendName: '', // 好友姓名
				page: {
					pageNum: 1,
					pageSize: 10
				},
				tabIndex: 1,
				deleteId: '',
			}
		},
		mixins: [navBarMixin],
		methods: {
			openPopup(e) {
				this.deleteId = e
				this.$refs.popup.open()
			},
			closePopup() {
				this.$refs.popup.close()
			},
			deletes(e) {
				console.log(12121212121);
				this.closePopup()
				if(!this.friendName) {
					deleteFriendCircle(this.deleteId).then(res=>{
						console.log(res);
						if(res.code==0) {
							this.getOwnFriendCircleList()
							uni.showToast({
								title:'删除成功！',
								icon:'none'
							})
						}else {
							uni.showToast({
								title:res.msg,
								icon:none
							})
						}
					})
				}
			},
			back(id) {
				uni.navigateBack()
			},
			async getOwnFriendCircleList() {
				const res = await getOwnFriendCircleApi(this.page)
				if (!res.code) {
					this.total = res.data.total
					var info = this.ownFirendList
					
					if (this.page.pageNum == 1) {
						this.ownFirendList = res.data.records
					}else {
						this.ownFirendList = info.concat(res.data.records)
					}
					this.isAll = this.ownFirendList.length == this.total ? 0 : 1
				}
			},
			
			async getFriendCircleList() {
				const res = await getCircleByFriendIdApi({ ...{friendId : this.friendId } ,...this.page})
				if(!res.code) {
					this.total = res.data.total
					var info = this.ownFirendList
					
					if (this.page.pageNum == 1) {
						this.ownFirendList = res.data.records
					}else {
						this.ownFirendList = info.concat(res.data.records)
					}
					this.isAll = this.ownFirendList.length == this.total ? 0 : 1
				}
			},
			
			
			
			details(item) {
				uni.navigateTo({
					url: '/pages/square/details?itemData=' + item.id
				})
			}
			
		},
		onLoad(options) {
			console.log('options===',options)
			this.firendCircleType = options.type
			this.friendId = options.userId ? options.userId : 0
			
			this.friendName = options.name ?  options.name : ''
			
			if(this.firendCircleType == 1) { // 1.查看自己的朋友圈。 2.查看别人的朋友圈
				this.getOwnFriendCircleList()
			}else {
				this.getFriendCircleList()
			}
			
		},
		onReachBottom() {
			if(this.isAll) {
				this.page.pageNum++
				
				if(this.firendCircleType == 1) {
					this.getOwnFriendCircleList()
				}else {
					this.getFriendCircleList()
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #f8f8f8;
	}

	.wf-box {
		overflow: hidden;

		.head {
			position: fixed;
			top: 0;
			z-index: 1;
			width: 100%;
			background: #fff;

			.head-np {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 100%;
				height: 96rpx;
				padding: 0 30rpx;
				box-shadow: 0rpx 10rpx 10rpx 0rpx rgba(50, 50, 50, 0.1);
				box-sizing: border-box;
				position: relative;

				.title {
					font-size: 36rpx;
					font-weight: bold;
				}
				.back {
					width: 20rpx;
					position: absolute;
					left: 30rpx;
				}
				
			}
		}

		.main {
			margin-top: 30rpx;

			.item {
				background-color: white;
				margin: 30rpx 0;
				padding: 30rpx;

				:nth-of-type(1) {

					// box-shadow: inset 20rpx 20rpx 100rpx rgba(213,213,213, 0.5);
				}
			}

			.item_top {
				display: flex;
				align-items: center;
				position: relative;

				>image {
					width: 90rpx;
					height: 90rpx;
					border-radius: 50%;
					margin-right: 20rpx;
				}

				.item_name {
					flex: 1;

					view {
						&:first-child {
							font-size: 30rpx;
							margin: 5rpx 0 14rpx 0;
							display: flex;
							align-items: center;

							image {
								width: 32rpx;
								margin-left: 10rpx;
							}
						}

						&:last-child {
							font-size: 26rpx;
							color: #999999;
						}
					}
				}

				.del {
					text-align: right;

					image {
						width: 72rpx;
						display: block;
						margin-left: auto;
					}
				}

				.item_time {
					font-size: 24rpx;
					color: #999999;
					margin-top: 28rpx;
				}
			}

			.comment {
				display: flex;
				align-items: center;
				margin-top: 30rpx;
				padding-bottom: 30rpx;
				border-bottom: 1rpx solid #DDDDDD;

				image {
					width: 62rpx;
					display: block;
				}

				input {
					flex: 1;
					height: 52rpx;
					background: #F2F2F2;
					border-radius: 31rpx;
					margin-left: 20rpx;
					font-size: 26rpx;
					padding: 0 30rpx;
				}
			}

			.warp {
				display: flex;
				font-size: 28rpx;
				margin-top: 20rpx;

				.text {
					.switch {
						float: right;
						clear: both;
						color: #FF5E5E;
						margin-right: 10rpx;
					}

					text {
						line-height: 40rpx;
					}
				}

				.text::before {
					content: '';
					width: 0rpx;
					height: calc(100% - 35rpx);
					background-color: red;
					float: right;
				}
			}

			.item_img {
				display: flex;
				flex-wrap: wrap;
				margin-top: 5rpx;

				.equall-img {
					width: calc(100% / 3);
					margin-top: 15rpx;
					box-sizing: border-box;
					overflow: hidden;
				
					image {
						width: 210rpx;
						height: 198rpx;
						display: block;
						border-radius: 8rpx;
					}
				
					&:nth-child(3n - 1) {
						image {
							margin: 0 auto;
						}
					}
				
					&:nth-child(3n) {
						image {
							margin-left: auto;
						}
					}
				}
			}

			.item_bottom {
				padding-bottom: 10rpx;
				padding-top: 20rpx;
				margin-top: 30rpx;
				font-size: 28rpx;
				color: #666666;
				border-top: 2rpx solid #DDDDDD;
			
				.like-box {
					display: flex;
			
					.like-list {
						flex: 1;
						margin-left: 20rpx;
			
						text {
							margin-right: 12rpx;
						}
					}
				}
				
				.firend-comments {
					display: flex;
					
					.comment-list {
						flex: 1;
						margin-left: 20rpx;
					}
				}
			
				image {
					width: 40rpx;
					height: 40rpx;
				}
			}

			.friend {
				text-align: center;

				image {
					width: 386rpx;
					margin-top: 400rpx;
				}

				view {
					font-size: 28rpx;
					color: #999999;
				}
			}
		}
		.popup-box {
			width: 583rpx;
			height: 630rpx;
			border-radius: 20rpx;
			box-sizing: border-box;
			background: #fff;
			background: url('../../static/img/me-32.png') no-repeat;
			background-size: cover;
			overflow: hidden;
			.popup-title {
				font-size: 32rpx;
				color: #333;
				font-weight: bold;
				text-align: center;
				margin-top: 290rpx;
			}
			.popup-sub {
				margin-top: 46rpx;
				color: #666;
				font-size: 28rpx;
				text-align: center;
			}
			.popup-footer {
				display: flex;
				justify-content: space-between;
				margin: 72rpx 52rpx 0;
				.cancle {
					width: 200rpx;
					line-height: 76rpx;
					text-align: center;
					border: 2rpx solid #3F93FF;
					border-radius: 40rpx;
					color: #3F93FF;
				}
				.confim {
					width: 200rpx;
					line-height: 76rpx;
					text-align: center;
					border-radius: 40rpx;
					background: #3F93FF;
					color: #fff;
				}
			}
		}
	}
</style>